package com.example.monitoringsystem.service.error;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.monitoringsystem.bean.Doctor;
import com.example.monitoringsystem.bean.Patient;
import com.example.monitoringsystem.bean.User;
import com.example.monitoringsystem.mapper.DoctorMapper;
import com.example.monitoringsystem.mapper.PatientMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;

import java.sql.Wrapper;
import java.util.List;

@Service
@Transactional
public class Patientinformationservice   {
    @Autowired
    PatientMapper patientMapper;
    @Autowired
            DoctorMapper doctorMapper;


    //确认用户是否存在
    public Patient findUserByAccount() {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        QueryWrapper<Patient> wrapper = new QueryWrapper<Patient>();
//        int id= Util.getCurrentUser().getId();
        wrapper.eq("patient_id",user.getId());
        Patient patient= patientMapper.selectOne(wrapper);
        return  patient;
    }
    public Doctor findDoctor()
    {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        Patient patient=this.findUserByAccount();
        QueryWrapper<Doctor> wrapper = new QueryWrapper<Doctor>();
        wrapper.eq("doctor_id",patient.getDoctor());
        Doctor doctor= doctorMapper.selectOne(wrapper);
        return  doctor;
    }
//
//    //修改医生
//    public void  updatdoctor(int doctor) {
////        int id = Util.getCurrentUser().getId();
//        UpdateWrapper<Patient> wrapper = new UpdateWrapper<>();
//        wrapper.set("doctor", doctor)
//                .eq("patient_id", user.getId());
//    }
    //药方没有权限修改

//        if (userMapper.update(new User(),wrapper)>0)
//        {
//            return 1;
//        }
//        else
//        {
//            return 0;
//        }

    }
//    //查找用户的信息
//        public List<Patient> getUserinformation(String  email) {
//            List<Patient> list = patientMapper.showinformation((Wrapper) new QueryWrapper().eq("email", email));
//            return  list;
//    }
////修改用户的密码
//    public void upateStu(String password,String email) {
//        patientMapper.upateStu(new UpdateWrapper<>().set("password", password).eq("email", email));
//
//    }
//   //修改用户名
//   public void upatename(String name,String email) {
//       patientMapper.upateStu(new UpdateWrapper<>().set("username", name).eq("email", email));
//
//   }
////   //修改医生
//    public void upatedescriprion(int doctor ,String email) {
//        patientMapper.upateStu(new UpdateWrapper<>().set("doctor", doctor).eq("email", email));
//    }
//    //修改性别
//    public void upategender(char gender,String email) {
//        patientMapper.upateStu(new UpdateWrapper<>().set("gender", gender).eq("email", email));
//
//    }
//    //修改医生
//    public void upatedeemail(String  email1 ,String email) {
//        patientMapper.upateStu(new UpdateWrapper<>().set("email", email1).eq("email", email));
//    }
//
//
//    }
//
